package com.xingkeduo.tool;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CheckDiffListUtils {

    public static boolean getDiffrent2(List<String> list1, List<String> list2) {
        long st = System.nanoTime();
        System.out.println("getDiffrent2 total times " + (System.nanoTime() - st));
        return !list1.retainAll(list2);
    }

    public static boolean getDiffrent(List<String> list1, List<String> list2) {
        long st = System.nanoTime();
        if (list1.size() != list2.size()) {
            System.out.println("getDiffrent total times " + (System.nanoTime() - st));
            return false;
        }
        for (String str : list1) {
            if (!list2.contains(str)) {
                System.out.println("getDiffrent total times " + (System.nanoTime() - st));
                return false;
            }
        }
        System.out.println("getDiffrent total times " + (System.nanoTime() - st));
        return true;
    }

    public static boolean getDiffrent4(List<String> list1, List<String> list2) {
        long st = System.nanoTime();
        Map<String, Integer> map = new HashMap<String, Integer>(list1.size() + list2.size());
        List<String> maxList = list1;
        List<String> minList = list2;
        if (list2.size() > list1.size()) {
            maxList = list2;
            minList = list1;
        }
        for (String string : maxList) {
            map.put(string, 1);
        }
        for (String string : minList) {
            Integer cc = map.get(string);
            if (cc != null) {
                map.put(string, ++cc);
                continue;
            }
            return false;
        }
        System.out.println("getDiffrent4 total times " + (System.nanoTime() - st));
        return true;
    }

    public static boolean getDiffrent5(List aList, List bList) {

        if (aList == bList)
            return true;

        if (aList.size() != bList.size())
            return false;

        int n = aList.size();
        int i = 0;
        while (n-- != 0) {
            if (aList.get(i).equals(bList.get(i)))
                return false;
            i++;
        }

        return true;
    }

}
